package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.EduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class EduController {
    @Autowired
    EduService eduService;
    //    各章节播放统计
    @RequestMapping("/chapterVideo")
    public Object chapterVideo(String nowDate){
        List<Map> list = eduService.chapterVideo(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray colArray = new JSONArray();

        JSONObject colObject = new JSONObject();
        colObject.put("name","视频播放次数");
        colObject.put("id","subsys");
        colArray.add(colObject);

        JSONObject colObject1 = new JSONObject();
        colObject1.put("name","累计播放时长");
        colObject1.put("id","module");
        colArray.add(colObject1);

        JSONObject colObject2 = new JSONObject();
        colObject2.put("name","（观看人数");
        colObject2.put("id","business");
        colArray.add(colObject2);

        JSONObject colObject3 = new JSONObject();
        colObject3.put("name","人均观看时长");
        colObject3.put("id","name");
        colArray.add(colObject3);

        JSONArray rowArray = new JSONArray();
        for (Map map : list) {
            JSONObject rowObject = new JSONObject();
            rowObject.put("subsys",map.get("NAME"));
            rowObject.put("module",map.get("vcount"));
            rowObject.put("business",map.get("sumcount"));
            rowObject.put("name",map.get("avgtime"));

            rowArray.add(rowObject);
        }
        dataObject.put("columns",colArray);
        dataObject.put("rows",rowArray);

        jsonObject.put("data",dataObject);
        return jsonObject;
    };
    //    各试卷成绩分布
    @RequestMapping("/examSocre")
    public Object examSocre(String nowDate){
        List<Map> list = eduService.examSocre(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray dataArray = new JSONArray();
        JSONObject dataObject = new JSONObject();
        dataObject.put("name","60分以下");
        dataObject.put("value",(Number)list.get(0).get("a"));

        System.out.println(list.get(0));
        dataArray.add(dataObject);
        JSONObject dataObject1 = new JSONObject();
        dataObject1.put("name","60到80分之间");
        dataObject1.put("value",list.get(0).get("b"));
        dataArray.add(dataObject1);
        JSONObject dataObject2 = new JSONObject();
        dataObject2.put("name","80到90分之间");
        dataObject2.put("value",list.get(0).get("c"));
        dataArray.add(dataObject2);
        JSONObject dataObject3 = new JSONObject();
        dataObject3.put("name","90到95分之间");
        dataObject3.put("value",list.get(0).get("d"));
        jsonObject.put("data",dataArray);
        dataArray.add(dataObject3);
        JSONObject dataObject4 = new JSONObject();
        dataObject4.put("name","95到100分之间");
        dataObject4.put("value",list.get(0).get("e"));
        dataArray.add(dataObject4);

        jsonObject.put("data",dataArray);
        return jsonObject;
    };
    //    各省份交易统计
    @RequestMapping("/provinceCount")
    public Object provinceCount(String nowDate){
        List<Map> list = eduService.provinceCount(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray mapArray = new JSONArray();
        for (Map map : list) {
            JSONObject mapObject = new JSONObject();
            mapObject.put("name",map.get("NAME"));
            mapObject.put("value",map.get("total"));
            mapArray.add(mapObject);
        }
        dataObject.put("mapData",mapArray);
        dataObject.put("valueName","交易总额");
        jsonObject.put("data",dataObject);
        return jsonObject;
    };
    //    交易综合统计
    @RequestMapping("/total")
    public Object total(String nowDate){
        List<Map> total = eduService.total(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",total.get(0).get("total"));
        return jsonObject;
    };
}
